package com.huluobo.h3kotlinproject.demo

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

/**
 * 2.创建Dao来进行数据库的增删改查
 *  Created by LC on 2023/10/19.
 *  @Insert 插入 onConflict = OnConflictStrategy.REPLACE 冲突策略,
 *  当插入时 在数据库中有相同的值(重复插入一个对象) 就会发生冲突,这里的冲突策略为替换
 *  增删改 基本都类似
 *  查需要填写一段SQL语句
 */
@Dao
interface UserDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUser(user: User)

    @Delete
    fun deleteUser(user: User)

    @Update
    fun updateUser(user: User)

    @Query("select * from user where user_id =:userId")
    fun queryUser(userId: String): User
}